package xyz.jangle.classp;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class M {
	
	private String name;

	public static void main(String[] args) {
		
		try {
			Class<?> class1 = Class.forName("xyz.jangle.classp.M");
			Object newInstance = class1.newInstance();
			M m = (M)newInstance;
			m.print();
			Method[] methods = class1.getDeclaredMethods();
			for(Method method:methods) {
				System.out.println(method.toString());
			}
			Method method = class1.getDeclaredMethod("print");
			System.out.println(method.toString());
			method.invoke(newInstance);
			Method methodSetName = class1.getDeclaredMethod("setName", String.class);
			methodSetName.invoke(newInstance, "123");
			Method methodPrintName = class1.getDeclaredMethod("printName");
			methodPrintName.invoke(newInstance);
			
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (NoSuchMethodException e) {
			e.printStackTrace();
		} catch (SecurityException e) {
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			e.printStackTrace();
		}

	}
	
	public void print() {
		System.out.println("hello");
	}
	
	public void printName() {
		System.out.println(name);
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	

}
